//
//  RunBuyOverTableViewCell.m
//  rrqs
//
//  Created by 杜文杰 on 2018/8/31.
//

#import "RunBuyOverTableViewCell.h"
@interface RunBuyOverTableViewCell()
@property (nonatomic, strong) UIImageView *headerImageView;
@property (nonatomic, strong) UILabel *orderIDLabel; // 订单号
@property (nonatomic, strong) UILabel *heJiLabel; // 合计
@property (nonatomic, strong) UILabel *dateLabel; // 日期
@property (nonatomic, strong) UILabel *bangNiMaiLabel; // 帮你买
@property (nonatomic, strong) UILabel *numberLabel; // 商品名
@property (nonatomic, strong) UIButton *bottomBtn; // 收货地址

@end

@implementation RunBuyOverTableViewCell
- (void)setDataDic:(NSDictionary *)dataDic
{
    self.orderIDLabel.text = [NSString stringWithFormat:@"订单号:%@",dataDic[@"order_id"]];
    self.heJiLabel.text = [NSString stringWithFormat:@"合计:%@元",dataDic[@"percentage"]];
    self.dateLabel.text = dataDic[@"add_time"];
    self.numberLabel.text = dataDic[@"title"];
    [self.bottomBtn setTitle:dataDic[@"map_location"] forState:UIControlStateNormal];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.separatorInset = UIEdgeInsetsZero;
        
        [self.contentView addSubview:self.headerImageView];
        
        // 配送费
        NSMutableArray *marray = @[].mutableCopy;
        marray = [self backUIViewWitTextStr:@""];
        UIView *psfView = marray[0];
        [self.contentView addSubview:psfView];
        __weak typeof(self)weakself = self;
        [psfView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakself.contentView.mas_top).offset(10 / HEIGHT_6S_SCALE);
            make.left.right.equalTo(weakself.contentView);
            make.height.mas_equalTo(20 / HEIGHT_6S_SCALE);
        }];
        self.orderIDLabel = marray[1];
        self.orderIDLabel.text = @"订单号:20192833792390";
        self.heJiLabel = marray[2];
        self.heJiLabel.text = @"合计99.6元";
        // 日期
        [marray removeAllObjects];
        marray = [self backUIViewWitTextStr:@"帮你买"];
        UIView *bangNiMaiView = marray[0];
        [self.contentView addSubview:bangNiMaiView];
        [bangNiMaiView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(psfView.mas_bottom).offset(10 / HEIGHT_6S_SCALE);
            make.left.right.equalTo(weakself.contentView);
            make.height.mas_equalTo(20 / HEIGHT_6S_SCALE);
        }];
        self.bangNiMaiLabel = marray[1];
        self.bangNiMaiLabel.textColor = getColor(blackColor);
        self.dateLabel = marray[2];
        self.dateLabel.text = @"2018-09-10 10:21:52";
        self.dateLabel.textColor = getColor(blackColor);

        //  数量
        UILabel *numberLabel = [[UILabel alloc]init];
        numberLabel.backgroundColor = [UIColor clearColor];
        numberLabel.textColor = getColor(blackColor);
        numberLabel.text = @"1";
        numberLabel.font = DEF_FontSize_14;
        self.numberLabel = numberLabel;
        [self.contentView addSubview:self.numberLabel];
        [numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakself.contentView.mas_left).offset(10 / WIDTH_6S_SCALE);
            make.top.equalTo(weakself.bangNiMaiLabel.mas_bottom).offset(10 / HEIGHT_6S_SCALE);
            make.height.mas_equalTo(20 / HEIGHT_6S_SCALE);
//            make.width.mas_equalTo(100 / WIDTH_6S_SCALE);
            make.right.equalTo(weakself.contentView).offset(-10 / WIDTH_6S_SCALE);

        }];
        
        UIButton *bottomBtn = [[UIButton alloc]init];
        bottomBtn.backgroundColor = getColor(whiteColor);
        [bottomBtn setTitleColor:getColor(textColor) forState:UIControlStateNormal];
        bottomBtn.titleLabel.font = DEF_FontSize_14;
        bottomBtn.titleLabel.textAlignment = NSTextAlignmentLeft;
        bottomBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        bottomBtn.titleLabel.numberOfLines = 2;
        bottomBtn.titleLabel.lineBreakMode = NSLineBreakByCharWrapping;
        bottomBtn.userInteractionEnabled = NO;
//        [bottomBtn setTitle:@"新民市东环街41号" forState:UIControlStateNormal];
//        [bottomBtn setImage:[UIImage imageNamed:@"ip"] forState:UIControlStateNormal];
//        [bottomBtn setImageEdgeInsets:UIEdgeInsetsMake(0, -300 / WIDTH_6S_SCALE, 0, 0)];
//        [bottomBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, -290 / WIDTH_6S_SCALE, 0, 0)];
//        [bottomBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
        self.bottomBtn = bottomBtn;
        [self.contentView addSubview:bottomBtn];
        [bottomBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(numberLabel.mas_bottom).offset(10 / HEIGHT_6S_SCALE);
            make.left.equalTo(weakself.contentView).offset(5 / HEIGHT_6S_SCALE);;
            make.right.equalTo(weakself.contentView).offset(-30 / HEIGHT_6S_SCALE);;
            make.height.mas_equalTo(40 / HEIGHT_6S_SCALE);
        }];
        UIImageView *rightImageView = [[UIImageView alloc]init];
        rightImageView.backgroundColor = [UIColor clearColor];
        rightImageView.image = [UIImage imageNamed:@"ip"];
        [self.contentView addSubview:rightImageView];
        [rightImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(bottomBtn.mas_centerY);
            make.right.equalTo(weakself.contentView.mas_right).offset(-10 / WIDTH_6S_SCALE);
//            make.height.mas_equalTo(20 / HEIGHT_6S_SCALE);
        }];
    }
    return self;
}
- (NSMutableArray *)backUIViewWitTextStr:(NSString *)textStr
{
    NSMutableArray *mArray = @[].mutableCopy;
    
    UIView *baseView = [[UIView alloc]init];
    baseView.backgroundColor = [UIColor clearColor];
    UILabel *leftLabel = [UILabel backLabelWithAlignment:@"1" contentStr:textStr bgcolor:whiteColor fontSize:DEF_FontSize_13];
    leftLabel.textColor = getColor(textColor);
    [baseView addSubview:leftLabel];
    leftLabel.frame = CGRectMake(10 / WIDTH_6S_SCALE,(baseView.frame.size.height * 0.5) - (leftLabel.frame.size.height * 0.5), 190 / WIDTH_6S_SCALE, 20 / HEIGHT_6S_SCALE);
    
    UILabel *rightLabel = [UILabel backLabelWithAlignment:@"2" contentStr:@"￥9" bgcolor:whiteColor fontSize:DEF_FontSize_13];
    rightLabel.textColor = getColor(textColor);
    [baseView addSubview:rightLabel];
    rightLabel.frame = CGRectMake(SCREEN_WIDTH - 150 / WIDTH_6S_SCALE - 10,(baseView.frame.size.height * 0.5) - (rightLabel.frame.size.height * 0.5), 150 / WIDTH_6S_SCALE, 20 / HEIGHT_6S_SCALE);
    [mArray addObject:baseView];
    [mArray addObject:leftLabel];
    [mArray addObject:rightLabel];
    return mArray;
}
@end
